#include "EncodeDOP.h"
#include "DecodeDSDFile.h" // for the ASSERT macro

uint8_t markers[] = {0x05, 0xFA};

// in_size must be divisable by 4.
// out must be of at least in_size*3/2 bytes.
void EncodeDOP::encode(uint8_t* in, int in_size, uint8_t* out)
{
    ASSERT(in_size % 4 == 0, "Bad number of bytes: " << in_size);

    int num_frames = in_size / 4; // Each USB sample is 16 bits. x2 stereo


    int marker_id = 0;
    for (int i = 0; i < num_frames; ++i)
    {
	*out++ = in[2];
	*out++ = in[0];
	*out++ = markers[marker_id];
	*out++ = in[3];
	*out++ = in[1];
	*out++ = markers[marker_id];
	in += 4;

	marker_id = marker_id ^ 1;
    }
}
